<?php
use Yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\widgets\LinkPager;

$this->title = '用户好友';
?>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav') ?>
        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">用户好友</h1>
            <div class="pull-right"></div>
          </div>
          
    <form id="user-search-form" class="form-inline well well-sm" action="<?php echo \Yii::$app->urlManager->createUrl('friend/search')?>" method="post" novalidate="">
	<!-- <?php $form = ActiveForm::begin(['id' => 'user-search-form'],['action'=>'friend/ss'],['method'=>'get'],['class'=>'form-inline well well-sm']); ?> -->
    <div class="form-group">
        <input id="nickname" name="nickname" class="form-control" placeholder="用户名/用户ID" type="text" value="<?php if(isset($user_name)){echo $user_name;}?>">
    </div>
		<?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?>
		<a class="btn btn-primary" href="javascript:void(0)" id="download">导出结果</a>
    <?php ActiveForm::end(); ?>

    <div class="table-responsive">
	<?php if(!isset($model)){?>
      <div class="empty">暂无好友</div>
	  <?php }else{?>
		<h3>当前查询用户:<font color='red'><?=$user['user_name']?></font></h3>
			<table class="table table-striped">
				<tr>
					<th>好友ID</th>
					<th>好友名</th>
					<th>添加时间</th>
				</tr>
				<?php 
					foreach($model as $k=>$v){
						echo "<tr>";
							echo "<td>".$v['user_num']."</td>";
							echo "<td>".$v['user_name']."</td>";
							echo "<td>".date('Y-m-d H:i:s',$v['add_time'])."</td>";
						echo "</tr>";
					}
				?>
            </table>
			<?php echo LinkPager::widget([
				'pagination' => $pagination,
				'firstPageLabel'=>"首页",
				'prevPageLabel'=>'上一页',
				'nextPageLabel'=>'下一页',
				'lastPageLabel'=>'尾页',
			]);?>
	  <?php }?>
    </div>

    </div></div>
  </div>

<script>
	$("#download").click(function(){
		var nickname = $("#nickname").val();
		if(nickname == ''){
			alert('请输入用户名或用户ID');
		}else{
			location.href="<?php echo \Yii::$app->urlManager->createUrl('friend/download')?>&nickname="+nickname;
		}
	});
</script>